#ifndef _TCP_H_
#define _TCP_H_

#include <compat_util.h>

#ifdef __cplusplus
extern "C" {
#endif

// sizeof(tcphdr_t) = 20
typedef struct tcphdr_s {
    uint16_t source; // source port
    uint16_t dest;   // dest   port
    uint32_t seq;    // sequence
    uint32_t ack_seq;
#if BYTE_ORDER == LITTLE_ENDIAN
    uint16_t res1 : 4;
    uint16_t doff : 4;
    uint16_t fin : 1;
    uint16_t syn : 1;
    uint16_t rst : 1;
    uint16_t psh : 1;
    uint16_t ack : 1;
    uint16_t urg : 1;
    uint16_t res2 : 2;
#elif BYTE_ORDER == BIG_ENDIAN
    uint16_t doff : 4;
    uint16_t res1 : 4;
    uint16_t res2 : 2;
    uint16_t urg : 1;
    uint16_t ack : 1;
    uint16_t psh : 1;
    uint16_t rst : 1;
    uint16_t syn : 1;
    uint16_t fin : 1;
#else
#error "BYTE_ORDER undefined!"
#endif
    uint16_t window;
    uint16_t check;   // checksum
    uint16_t urg_ptr; // urgent pointer
} tcphdr_t;

#ifdef __cplusplus
}
#endif

#endif //_TCP_H_
